package com.ljm.controller;/**
 * @author： li
 * @date： 2022-05-06 14:26
 * @version 1.0
 */

import com.opensymphony.xwork2.ActionSupport;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import java.io.File;

/**
 * @author： ljm
 * @date： 2022-05-06 14:26
 * @version 1.0
 */
public class uploadAction extends ActionSupport {
    //两个属性名跟jsp的form属性的name一样
    //这样struts2框架会自动复制，每个属性需要getter和setter
    private File file;
    private String fileContentType;
    private String fileFileName;

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String getFileContentType() {
        return fileContentType;
    }

    public void setFileContentType(String fileContentType) {
        this.fileContentType = fileContentType;
    }

    public String getFileFileName() {
        return fileFileName;
    }

    public void setFileFileName(String fileFileName) {
        this.fileFileName = fileFileName;
    }

    @Override
    public String execute() throws Exception {
        System.out.println(fileFileName);
// /usr/local/tomcat/apache-tomcat-9.0.62/webapps/wxapp/upload/meigui.jpg
        String to = ServletActionContext.getServletContext().getRealPath("/upload/"+fileFileName);
//        String to = "E://img//images"+fileName;
        System.out.println(to);
//        String imageurl="http://119.91.198.127:8080/wxapp/upload/"+fileFileName;
        File toFile =new File(to);
        FileUtils.copyFile(file,toFile);

        return ActionSupport.SUCCESS;
    }
}
